<!DOCTYPE html>
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>

</head>
<body>
  <div id="app">
    <button @click="isShow = !isShow">{{isShow?'隐藏':'显示'}}</button>
    <hr>
    <common-head v-if="isShow"></common-head>
  </div>

  <script src="./vue.js"></script>
  <script>
    const CommonHead = {
      template: `
      <div>
        <button @click="addArr">增加li</button>
        <h3>这是头部组件</h3>
        <ul>
          <li v-for="item in arr" :key="item">
            {{item}}  
          </li>  
        </ul>
      </div>
      `,
      data(){
        return {
          arr: [1,2,3,4]
        }
      },
      methods:{
        addArr(){
          this.arr.push(this.arr.length+1);
          // console.log(document.querySelectorAll('li'), 111);
          this.$nextTick(() => {
            console.log(document.querySelectorAll('li'), 111);
          })
        }
      },
      updated(){
        console.log(document.querySelectorAll('li'), 222);
      }
    };
    Vue.component('CommonHead', CommonHead)
    const vm = new Vue({
      el: '#app',
      data: {
        isShow: true
      }
    })
    
  </script>
</body>
</html>